package com.hui.tally.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hui.tally.R;
import com.hui.tally.db.BookBean;

import java.util.List;

public class AddBookAdapter extends BaseAdapter {
    private Context mContext;
    List <BookBean> mdatas;
    public AddBookAdapter(Context Context , List<BookBean> datas) {
        this.mContext = Context;
        this.mdatas = datas;
    }

    @Override
    public int getCount() {
        return mdatas.size();
    }

    @Override
    public Object getItem(int i) {
        return mdatas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        convertView = LayoutInflater.from(mContext).inflate(R.layout.item_add_book_gv,viewGroup,false);
        //查找布局当中的控件
        TextView tv = convertView.findViewById(R.id.item_add_book_tv);
        //获取指定位置的数据源
        BookBean bookBean = mdatas.get(i);
        tv.setText(bookBean.getBookname());
        tv.setBackgroundResource(bookBean.getColorId());
        return convertView;
    }
}
